package edu.xidian.sselab.cloudcourse.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import edu.xidian.sselab.cloudcourse.domain.test1_entity;
import edu.xidian.sselab.cloudcourse.repository.test1_Repository;
import org.omg.CORBA.Object;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.ui.Model;




import java.util.List;


@Controller

public class test1_controller {

    @Autowired
    private test1_Repository test1_repository;

    @RequestMapping("/test1")

    public String test1_try(Model model) { //要求1的controller
        model.addAttribute("title", "所有汽车全国各月总销量走势");
        return "test1"; //跳转到test1页面
    }

    @RequestMapping("/test17")
    public @ResponseBody List test1_try2() throws IOException { //要求1的controller

        String start = "201907"; //开始时间

        String end = "202006"; //结束时间

        List<test1_entity> recordList = test1_repository.find(start,end); //根据要求查找数据

        List<String> dates=new ArrayList<>();
        List<String> salenumbers=new ArrayList<>();
        Map<String,List> map = new HashMap<String,List>();
        System.out.println("以下是201907到202006的销售数据：");

        for(test1_entity t:recordList){//把找到的每一条数据打印出来
            dates.add(t.Date);
            salenumbers.add(t.salenumber);

            System.out.println(t);
        }




        return recordList;
    }
}
